<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>首页</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../../../css/mui.min.css" rel="stylesheet" />
    <link href="../css/common.css" rel="stylesheet" />
    <style>
      /*九宫格样式*/
      *{ touch-action: pan-y; }
      .home_icon {
      	width: 100%;
      }
      
      .mui-icon {
      	width: 100%;
      	padding: 0 26%;
      }
      
      .mui-grid-view.mui-grid-9 {
      	background: #fff;
      	padding: 10px 0;
      }
      
      .mui-grid-view.mui-grid-9 .mui-table-view-cell {
      	border: none;
      	padding: 5px 15px;
      }
      /*图标样式*/
      
      #lineChart {
      	width: 100%;
      	height: 340px;
      	background: #fff;
      	padding: 16px 15px;
      	margin-top: 10px;
      }
      
    </style>
  </head>
  <body>
    <div id="container">
      <!--
      <header class="mui-bar mui-bar-nav">
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
        <h1 class="mui-title">外来人员管理</h1>
      </header>
	  -->
      <div class="mui-content">
        <div id="slider" class="mui-slider">
          <div class="mui-slider-group mui-slider-loop">
            <!-- 额外增加的一个节点(循环轮播：第一个节点是最后一张轮播) -->
            <div class="mui-slider-item mui-slider-item-duplicate">
              <a href="javascript:;">
                <img src="../img/img.png">
              </a>
            </div>
            <!-- 第一张 -->
            <!-- <div class="mui-slider-item">
                <a href="#">
                  <img src="../img/img.png">
                </a>
              </div> -->
            <!-- 第二张 -->
            <!-- <div class="mui-slider-item">
                <a href="#">
                  <img src="../img/img.png">
                </a>
              </div> -->
            <!-- 第三张 -->
            <!-- <div class="mui-slider-item">
                <a href="#">
                  <img src="../img/img.png">
                </a>
              </div> -->
            <!-- 第四张 -->
            <!-- <div class="mui-slider-item">
                <a href="#">
                  <img src="../img/img.png">
                </a>
              </div> -->
            <!-- 额外增加的一个节点(循环轮播：最后一个节点是第一张轮播) -->
            <!-- <div class="mui-slider-item mui-slider-item-duplicate">
                <a href="#">
                  <img src="../img/img.png">
                </a>
              </div> -->
          </div>
          <div class="mui-slider-indicator">
            <div class="mui-indicator mui-active"></div>
            <!--
              <div class="mui-indicator"></div>
              <div class="mui-indicator"></div>
              <div class="mui-indicator"></div>
			  -->
          </div>
        </div>
        <ul class="mui-table-view mui-grid-view mui-grid-9">
          <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="project">
            <a href="#">
              <span class="mui-icon ">
                <img src="../img/project.png" class="home_icon" />
              </span>
              <div class="mui-media-body">关联项目</div>
            </a>
          </li>
          <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="course">
            <a href="#">
              <span class="mui-icon ">
                <img src="../img/course.png" class="home_icon" />

              </span>
              <div class="mui-media-body">我的课程</div>
            </a>
          </li>
          <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="exam">
            <a href="#">
              <span class="mui-icon ">
                <img src="../img/reusult.png" class="home_icon" />
              </span>
              <div class="mui-media-body">考试</div>
            </a>
          </li>
          <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="notice">
            <a href="#">
              <span class="mui-icon ">
                <img src="../img/notice.png" class="home_icon" />

              </span>
              <div class="mui-media-body">入场须知</div>
            </a>
          </li>
          <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="safe">
            <a href="#">
              <span class="mui-icon ">
                <img src="../img/safe.png" class="home_icon" />

              </span>
              <div class="mui-media-body">安全承诺</div>
            </a>
          </li>
          <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="record">
            <a href="#">
              <span class="mui-icon ">
                <img src="../img/record.png" class="home_icon" />

              </span>
              <div class="mui-media-body">登记记录</div>
            </a>
          </li>
        </ul>
      </div>
  </body>

  <script src="../../../js/mui.min.js"></script>
  <script src="../../../js/jquery-1.7.2.min.js"></script>
  <script src="../../../js/vue.js"></script>
  <script src="../js/mkeyplus.base.js"></script>
  <script src="../formal/js/api.js"></script>
  <script type="text/javascript" charset="utf-8">
    var htapi = new HTGlobal();
    var daysStatus=null;//是记录项目工作时长的，预计工期时长：1，大于10天；2，小于等于10天
    var appUserId="";//当前用户id
    mui.init({
      swipeBack: true //启用右滑关闭功能
    });
    var slider = mui("#slider");
    /*	
        slider.slider({
          interval: 3000
        });
		*/
    $('#record').on('tap', function() {
      
                mui.openWindow({
                  url: '../record/index.html',
                  id: '../record/index.html',
                  extras: {},
                  waiting: {
                    autoShow: false
                  }
                })
             
    });
    $('#project').on('tap', function() {
		mui.toast('功能正在完善中，敬请期待！');return;
      mui.openWindow({
        url: '../project/project.html',
        id: '../project/project.html',
        extras: {},
        waiting: {
          autoShow: false
        }
      })
    });
    $('#notice').on('tap', function() {
		openSafe();return;
      if(daysStatus==1){//项目周期大于十天
        getCourseStatus(function(data){
          if(data){
            getExamStatus(function(data){
              if(data){
               openSafe();
              }
            }) 
          }
        })
      }else if(daysStatus==2){//项目小于等于10天
        getCourseStatus(function(data){//完成课程观看后才能点击进去
          if(data){
            openSafe()
          }
        })
      }   
    });
    function openSafe(){//打开入场须知
      var user = localStorage.getItem('outUser'),
        openPath = '../formal/registration_on.html';
      //console.log(user);return;
      if (user) {
        user = JSON.parse(user);
        if (user.notice && user.notice != 0) {
          openPath = './admission.html';
        }
      }
      //console.log(openPath);return;	
      mui.openWindow({
        url: openPath,
        id: openPath,
        extras: {},
        waiting: {
          autoShow: false
        }
      })
    }
    $('#safe').on('tap', function() {
     
                mui.openWindow({
                  url: './safe.html',
                  id: './safe.html',
                  extras: {},
                  waiting: {
                    autoShow: false
                  }
                })
  
      
      
    });
    $('#course').on('tap', function() {
		mui.toast('功能正在完善中，敬请期待！');return;
      mui.openWindow({
        url: '../course/myCourse.html',
        id: '../course/myCourse.html',
        extras: {},
        waiting: {
          autoShow: false
        }
      })
    });
    $('#exam').on('tap', function() {
      getCourseStatus(function(data){//完成课程观看后才能去考试
        if(data){
          mui.openWindow({
            url: '../course/course.html',
            id: '../course/course.html',
            extras: {},
            waiting: {
              autoShow: false
            }
          })
        }
      }) 
    });
    var first = null; //第一次点击backbutton
    mui.plusReady(function() {
      var new_back = mui.back;
      mui.back = function() {
        //首次按键，提示‘再按一次退出应用’
        if (!first) {
          first = new Date().getTime();
          mui.toast('再按一次退出应用');
          setTimeout(function() {
            first = null;
          }, 800);
        } else {
          if (new Date().getTime() - first < 1000) {
            plus.runtime.quit();
          }
        }
      }
      var user = htapi.getOsUser();
      console.log(user);
      appUserId=user.id;
      getStatus(user.id)
      // getExamStatus()
    })
    function getStatus(id,callback){
      
      mui.baseWApp.httpRequst("/outsider/app/getUserInfo/"+id, {
      }, function(data) {
        console.log('获取天数'+ JSON.stringify(data))
        if(data.code=='0'){
          daysStatus=data.data.daysStatus || 0
          // daysStatus=2
        }
		if(callback && typeof(callback)=='function'){
			callback(data)
		}
      }, function() {
        plus.nativeUI.closeWaiting();
        console.log("获取数据失败");
      })
    }
    function getCourseStatus(callback){//获取课程状态
      var Status=false;
      mui.baseWApp.httpRequst("/outsider/app/course/findCourseStatus/" + appUserId, {
      }, function(data) {
        console.log('获取课程状态'+ JSON.stringify(data))
        if(data.code=='0'){
          Status=true; 
        }else{
          Status=false
          mui.toast(data.msg) 
        }
        callback(Status);
      }, function() {
        plus.nativeUI.closeWaiting();
        console.log("获取数据失败");
      })
      
    }
     function getExamStatus(callback){//获取考试状态
      var Status=false;
      mui.baseWApp.httpRequst("/outsider/app/exam/findExamStatus/" + appUserId, {
      }, function(data) {
        console.log('获取考试状态'+ JSON.stringify(data))
        if(data.code=='0'){
          Status=true; 
        }else{
          Status=false
          mui.toast(data.msg) 
        }
        callback(Status);
      }, function() {
        plus.nativeUI.closeWaiting();
        console.log("获取数据失败");
      })
    }
  </script>

</html>
